package com.itheima.dao;

import com.itheima.pojo.Member;
import com.itheima.pojo.Order;
import com.itheima.pojo.Setmeal;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface OrderSettingListDao {
    /*=====================select=====================*/
    /*@Update({"<script>",
      "update Author",
      "  <set>",
      "    <iftest='username != null'>username=#{username},</if>",
      "    <if test='password != null'>password=#{password},</if>",
      "    <if test='email != null'>email=#{email},</if>",
      "    <if test='bio != null'>bio=#{bio}</if>",
      "  </set>",
      "where id=#{id}",
      "</script>"})*/
    /**
     * 查找全部order
     * @return
     */
    /*@Select("select id,member_id memberId,orderDate,orderType,orderStatus,setmeal_id setmealId from t_order")
    List<Order> findAll();*/
    //select id,member_id memberId,orderDate,orderType,orderStatus,setmeal_id setmealId from t_order" +
    //            "<if test='startDate !=  null &&  endDate != null '> AND a.`articleType`= #{articleType} </if>
    @Select({"<script>" +
            "select id,member_id memberId,orderDate,orderType,orderStatus,setmeal_id setmealId from t_order" +
            "<where> 1 = 1" +
            "<if test = 'startDate != null &amp; endDate != null'> AND orderDate between #{startDate} and #{endDate} </if>" +
            "<if test = 'queryStatus != null'> AND orderStatus = #{queryStatus} </if>" +
            "<if test = 'queryType != null'> AND orderType = #{queryType} </if>" +
            "<if test = 'memberId != null'> AND member_id = #{memberId} </if>" +
            "</where>" +
            "</script>"})
    List<Order> findAll(@Param("startDate") String startDate,@Param("endDate") String endDate,@Param("queryStatus") String queryStatus,@Param("queryType") String queryType,@Param("memberId") Integer memberId);

    /**
     * 根据memberId查找member
     * @param id
     * @return
     */
    @Select("select * from `t_member` where id = #{id}")
    Member findMemberById(Integer id);

    /**
     * 根据msetmealId查找setmeal
     * @param id
     * @return
     */
    @Select("select * from `t_setmeal` where id = #{id}")
    Setmeal findSetmealById(Integer id);

    /**
     * 为新增预约查找所有套餐信息
     * @return
     */
    @Select("select * from `t_setmeal`")
    List<Setmeal> findAllSetMeal();

    /**
     * 根据手机号查找对应的member
     * @param phoneNumber
     * @return
     */
    @Select("select * from `t_member` where phoneNumber = #{phoneNumber}")
    Member findMemberByPhoneNumber(String phoneNumber);

    /**
     * 根据会员名查找对应的member
     * @param queryString
     * @return
     */
    @Select("select * from `t_member` where name = #{queryString}")
    Member findMemberByName(String queryString);
    /*=====================insert=====================*/

    /**
     * 新增用户
     * @param member
     * @return
     */
    @Insert("insert into t_member values(0,null,#{name},null,null,#{phoneNumber},#{regTime},null,null,null,null)")
    boolean addMember(Member member);

    @Insert("insert into t_order values(0,#{memberId},#{orderDate},#{orderType},#{orderStatus},#{setmealId})")
    void addOrder(Order order);


    /*=====================update=====================*/

    /**
     * 根据orderId修改指定order
     * @param order
     */
    @Update("update t_order set " +
            "setmeal_id = #{setmealId}," +
            "orderDate = #{orderDate}," +
            "orderType = #{orderType}," +
            "orderStatus = #{orderStatus}" +
            "where id = #{id}")
    void editOrderByOrderId(Order order);

    /**
     * switch发生变动时修改
     * @param order
     */
    @Update("update t_order set " +
            "orderStatus = #{orderStatus}" +
            "where id = #{id}")
    void editOrderStatus(Order order);
    /*=====================delete=====================*/

    /**
     * 根据orderId删除指定order
     * @param id
     */
    @Delete("delete from t_order where id = #{id}")
    void deleteOrderById(Integer id);

}
